OOP  - Assignment 7

Topic:               Inheritance

Points:              25

Due:                 3-9-2004

Instructor:      Dana Steil

 


 General Overview:

You will be creating a time class, an alarm clock, a radio and a radio alarm clock.

            This is only as simulation; your radio alarm clock will not actually function.

 

Files to be turned in:


Time.h

Time.cpp

AlarmClock.h

AlarmClock.cpp

Radio.h

Radio.cpp

RadioAlarmClock.h

RadioAlarmClock.cpp


 Specifications:

 Enumeration ETimeFormat

  1. Add an enumeration for the Time Format (Universal and Standard).   This enumeration should be created in the same file as CTime but before the class definition.

enum ETimeFormat

{

      Universal = 0,

      Standard

};

 

Class CTime – Your CTime class should be based on the Time class in your book on pages 491-494.

Changes from the books Time Class:

·        Change the variable names and any other programming style to fit what you have been taught in class.  For example make the class name CTime instead of Time.

·        Add a member variable named “m_Format” of type ETimeFormat.  The member variable should default to Standard.

·        Add a public set function for “m_Format”.

·        Overload the stream insertion operator to display the time in the format indicated by “m_Format”.  You are still required to use the “PrintUniversial” and “PrintStandard” functions; they should now be private.

 

Class Alarm Clock – Inherits from (is a) CTime. 

 

  1. The alarm clock is unique in the fact that while it “is a” CTime, it also keeps track of another time; the alarm time.  To keep track of the alarm time, add a private member variable of type CTime named m_AlarmTime.

 

  1. Add a public member function to the class to set the alarm’s time (SetAlarm).  This function should take the same parameters as the SetTime() in the time class.  As a matter of fact it should call that function on the m_AlarmTime object.

 

  1. Override the inherited function SetFormat().  This function should now set the format for the time and the alarm time.

 

  1. Override the inherited function PrintUniversial ().  This function should now print the time in the military format for both the time and the alarm time.  Make your output describe which time is which.

 

  1. Override the inherited function PrintStandard().  This function should now print the time in the standard format for both the time and the alarm time.  Make your output describe which time is which.

 

  1. Overload the stream insertion operator to display the time & alarm time in the format indicated by “m_Format”.  

 

Enumeration EBand

  1. Add an enumeration for the band, AM and FM.   This enumeration should be created in the same file as CRadio but before the class definition.
  2. Overload the stream insertion operator to display the band. 

 

enum EBand

{

   AM = 0,

   FM

};

 

Class Radio

  1. Static Constants: remember to initialize at file level. All of them should be integers.

 

    1. MAX_FREQUENCY = 110
    2. MIN_FREQUENCY = 85
    3. MAX_AMPLITUDE = 1750
    4. MIN_AMPLITUDE = 500
    5. MAX_VOLUME = 100

 

  1. Add a default constructor that takes two parameters (band and volume).  Default the band to FM, the station to 100.1 and the volume to 30.
  2. Add a set station function (SetStation) that accepts a new station as its only parameter.  This function should do bounds checking to make sure the station is within an expectable frequency or amplitude.  This function should return true if the new station value is accepted false otherwise. 
  3. Add a set volume (SetVolume) function that accepts a new station as its only parameter.  This function should do bounds checking to make sure the volume is greater than or equal to 0 and less than or equal to MAX_VOLUME. This function should return true if the new volume value is accepted false otherwise. 
  4. Add a set band (SetBand) function that will set the band to AM or FM.  This function should take one parameter of type EBand.   When switching from one band to another, be sure to set the station correctly.  AM = ((FM-85)*50)+500  and FM = ((AM-500)/50)+85. 
  5. Overload the stream insertion operator to display the radio. 
  6. The class should contain the following private data members.
    1. float m_Station;
    2. int m_Volume;
    3. EBand m_Band;

 

Class Radio Alarm Clock – inherits form CRadio and CAlarmClock (is a radio and is an alarm clock)

1.                Add a default constructor that will default the band to FM, the station to 100.1 and the volume to 30.

2.                Overload the stream insertion operator to display the radio alarm clock.